package com.hzz.mybatisplusdemo.student.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hzz.mybatisplusdemo.config.sqlInjector.GeneralServiceImpl;
import com.hzz.mybatisplusdemo.student.entity.Student;
import com.hzz.mybatisplusdemo.student.mapper.StudentMapper;
import com.hzz.mybatisplusdemo.student.service.IStudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hzz
 * @since 2021-08-09
 */
@Service
public class StudentServiceImpl extends GeneralServiceImpl<StudentMapper, Student> implements IStudentService {


    public Student findStundetById(Integer id) {
        Student byId = getById(id);
     //   updateById(Student.builder().id(1).name("测试2").build());
        return byId;
    }


    public void saveStudent(){
        Student student=new Student();

    }

    public List<Student> selectList(){
        List<Student> students = list(null);
        return  students;
    }

    // @Async
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_UNCOMMITTED)
    public void test() {
        log.debug("异步保存");
        Student byId1 = getById(1);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        getOne(Wrappers.lambdaQuery(byId1));

        Student byId2 = getById(1);
        save(Student.builder().id(6).name("测试6").build());
        Student byId = getById(6);
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // test1();

    }
}
